# -*- coding: UTF-8 -*-

# style sheet parameter parsing
class sheet_property(object):
	def __init__(self):
		self.val = None
		
	def apply(self,pseudo,styles):
		if self.val != None:
			return self.val

# common sheet parameter
class IntValueApply(sheet_property):
	def set(self,name,attr):
		try:
			self.val = int(attr)
		except ValueError:
			print "Invalid value for property '%s'." %name

class FloatValueApply(sheet_property):
	def set(self,name,attr):
		try:
			self.val = float(attr)
		except ValueError:
			print "Invalid value for property '%s'." %name

class StrValueApply(sheet_property):
	def set(self,name,attr):
		try:
			self.val = str(attr)
		except ValueError:
			print "Invalid value for property '%s'." %name

class PairIntValueApply(sheet_property):
	def set(self,name,attr):
		val = attr.split(',')
		try:
			for i in xrange(len(val)):
				val[i] = int(val[i])
		except ValueError:
			print "Invalid value for property '%s'." %name
			return
		if len(val) == 1:
			self.val = (val[0],val[0])
		elif len(val) == 2:
			self.val = (val[0],val[1])
		else:
			print "Invalid value for property '%s'." %name
